package com.atung.dao;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;

import com.atung.model.BusRoutPublish;
import com.atung.model.BusRoutPublishDTO;
import com.atung.provider.BusRoutPublishProvider;

@Mapper
public interface BusRoutPublishDAO {


	/**
	 * 获取车次列表
	 * @param RoutId
	 * @param startData
	 * @return
	 */
	@SelectProvider(type=BusRoutPublishProvider.class,method="selectRoutPublishByRoutIdProvider")
	List<BusRoutPublishDTO>selectBusRoutPublishByRoutIdAndStartData(@Param("routId")Long routId,@Param("startData")Date startData);

	/**
	 * 详情
	 * @param publisId
	 * @return
	 */
	@SelectProvider(type=BusRoutPublishProvider.class,method="selectRoutPublishByIdProvider")
	BusRoutPublishDTO selectBusRoutPublishMessageById(@Param("publisId")Long publisId);
	
	
	/**
	 * 根据id获取发布信息
	 * @param Id
	 * @return
	 */
	@Select("select * from bus_rout_publish where id=#{Id}  and is_delect=0")
	BusRoutPublish selectBusRoutPublishById(@Param("Id")Long Id);
	
	/**
	 * 修改报名人数
	 * @param Id
	 * @param carCurrentNumber
	 * @return
	 */
	@Update("update bus_rout_publish set car_current_number=car_current_number+#{carCurrentNumber} where id=#{Id} and is_delect=0 and rout_publish_state=600")
	Boolean updateCarCurrentNumberById(@Param("Id")Long Id,@Param("carCurrentNumber") Integer carCurrentNumber);
	
	/**
	 * 修改发布状态（路线状态（601不可报名 600可报名））
	 * @param publisId
	 * @param publishState
	 * @return
	 */
	@Update("update bus_rout_publish set rout_publish_state=#{publishState} where id=#{publisId} and is_delect=0 ")
	Boolean updateBusRoutPublishByRoutPublishState(@Param("publisId")Long publisId,@Param("publishState")Integer publishState);

	/**
	 * 查看锁状态
	 * @param id
	 * @return
	 */
	@Select("select lock_state from bus_rout_publish  where id=#{Id}")
	Integer lockStatePublishById(@Param("Id")Long Id);
	/**
	 * 解锁
	 * @param Id
	 * @return
	 */
	@Update("update bus_rout_publish set lock_state=0 where id=#{Id}")
	Boolean unlockPublishById(@Param("Id")Long Id);
	
	/**
	 * 上锁
	 * @param Id
	 * @return
	 */
	@Update("update bus_rout_publish set lock_state=1 where id=#{Id}")
	Boolean lockPublishById(@Param("Id")Long Id);
}
